<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<script>
  // 1.数字转字符
  var num = 10;
  var str = num.toString();
  console.log(str); // => (String)10
  console.log(String(num)); // => (String)10
  console.log(num + ''); // => (String)10 最常用

  // 2.字符转数字
  //2.1 parseInt 取整
  console.log(parseInt('3.555')); // => 3
  console.log(parseInt("333aaa")); // => 333
  console.log(parseInt('aaa333aaa')); // => NaN
  //2.2 parseFloat 得到浮点数
  console.log(parseFloat('3.555')); // => 3.555
  console.log(parseInt("333.555aaa")); // => 333
  console.log(parseInt('aaa333aaa')); // => NaN
  //2.3 强制类型转化
  console.log(Number('12')); // => (Number)12
  //2.4 隐式转化
  console.log("12" - 0); // => (Number)12
  console.log("12" - "10"); // => (Number)2
  console.log("12" * 1); // => (Number)12

    // 3.任何类型转Boolean
  console.log(Boolean("")); // => false
  console.log(Boolean(0));  // => false
  console.log(Boolean(NaN)); // => false
  console.log(Boolean(null));// => false
  console.log(Boolean(undefined));// => false
  // 其余均为 true，可当作是否非空的判断


</script>
<body>

</body>
</html>